Page({
  data: {
    encryptedData: '',
    houseInfo: '',
    id: '',
    url: '',
    validTime: ""
  },
  onLoad({ id, encrypted }) {
    if (id) {
      this.getVistitorDatail(id)
    } else {
      this.getVisitorDetail2(encrypted)
    }

  },
  async getVistitorDatail(id) {
    const res = await wx.http({
      url: '/visitor/' + id
    })
    this.setData(res.data)
  },
  async getVisitorDetail2(encrypted) {
    const res = await wx.http({
      url: `/visitor/share/${encrypted}`
    })

    this.setData(res.data)
  },
  onShareAppMessage() {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index?encrypted=' + this.data.encryptedData,
      imageUrl: 'https://enjoy-plus.oss-cn-beijing.aliyuncs.com/images/share_poster.png',
    }
  },
  async onSavImageToPhotosAlbtm() {
    const { path } = await wx.getImageInfo({ src: this.data.url })
    const res = await wx.saveImageToPhotosAlbum({
      filePath: path
    })
    console.log(res)
  }

})
